package com.kai.controller;

import com.alibaba.fastjson.JSONObject;
import com.kai.Util.ResultMsg;
import com.kai.Util.ResultStatusCode;
import com.kai.entity.WalletBlockHeight;
import com.kai.entity.WalletFinance;
import com.kai.service.ExportService;
import com.kai.service.WalletService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * Created by zhangkai on18/8/3
 *获取用户列表
 */
@Component
@RestController
@RequestMapping("/blockScan")
public class BlockScanManageController {

    private static Logger log = LoggerFactory.getLogger(WalletPalteListController.class);

    private final  static Integer NUM=1;

    private final  static Integer SIZE=10;
    @Autowired
    WalletService walletService;
    @Autowired
    ExportService exportService;


    /**
     * 区块高度管理
     * @param
     * @return
     */
    @PostMapping (value = "/getHeight")
    @ResponseBody
    public ResultMsg  getHeight(@RequestBody JSONObject request){
        return  new ResultMsg(ResultStatusCode.OK.getCode(), ResultStatusCode.OK.getMsg(), walletService.selectBlockheight(1));
    }



    @PostMapping (value = "/updateWalletHeight")
    @ResponseBody
    public ResultMsg  updateWalletHeight(@RequestBody JSONObject request){
        WalletBlockHeight wbp=new WalletBlockHeight();

        if(request.get("blockHeight") !=null && !request.get("blockHeight").equals("")){
            wbp.setBlockHeigth(Integer.valueOf(request.get("blockHeight").toString()));
        }
        if(request.get("flag") !=null && !request.get("flag").equals("")){
            wbp.setFlag(Boolean.valueOf(request.get("flag").toString()));
        }
        Boolean i=walletService.updateBlockheight(wbp);
        ResultMsg resultMsg;
        if(i.equals(true)){
            resultMsg = new ResultMsg(ResultStatusCode.OK.getCode(), ResultStatusCode.OK.getMsg(), i);
        }else{
            resultMsg = new ResultMsg(ResultStatusCode.EORROR.getCode(), ResultStatusCode.OK.getMsg(), i);
        }
        return resultMsg;
    }
}